HAL SMBUS migration: List of applicable concepts

This section provides information about the HAL SMBUS applicable architecture concepts.

Concepts for SMBUS

Concept

Description

Separation of initialization and configuration functions

The initialization has been split into separate init and config functions:

  • HAL_SMBUS_Init: This function is responsible for creating and setting up the handle object.

  • HAL_SMBUS_SetConfig: It sets parameters such as clock speed, addressing mode, and other operational settings.

Removal and conversion of init structure to configuration structure

The init structure has been removed and moved into hal_smbus_config_t configuration structure.

Renaming of the handle structure

The handle structure has been renamed to hal_smbus_handle_t.

Renaming unitary init structures

The structure SMBUS_InitTypeDef is no longer available and has been replaced by hal_smbus_config_t.

Remove MspInit and MspDeInit callbacks

HAL_SMBUS_MspInit and HAL_SMBUS_MspDeInit are no longer available and have been replaced by a user sequence to initialize and configure the SMBUS.

Unitary configuration APIs

New APIs are available to get and set SMBUS features.

Introduction of HAL user data set/get APIs

Two functions to Set/Get User Data are available: HAL_SMBUS_SetUserData and HAL_SMBUS_GetUserData.

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each SMBUS event.

HAL implementation with LL inline functions

HAL SMBUS APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL SMBUS define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL SMBUS driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

The SMBUS state machine is reworked to ensure transitions of the peripheral functional states

Revised and optimized HAL API status returns

The HAL SMBUS functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_BUSY: in case of an ongoing process.

  • HAL_OK: in case of a successfully completed operation.

Revised and optimized HAL error management

The HAL error handling mechanisms have been redesigned to improve the detection, reporting, and handling of errors.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL SMBUS driver have been removed and replaced by _t.

Replaced multi-line macros with inline functions

For the HAL SMBUS driver, large macros have been replaced by inline functions to maintain code consistency, improve readability, and benefit from compiler optimization. Inline functions also offer better support for debugging and strict type management, reducing the risk of errors.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros.

Merge HAL extension files with common ones and remove the EX prefix from APIs.

Only one HAL SMBUS header file remains and all macros, define statements, and functions from hal_smbus_ex.h have been moved to hal_smbus.h.

Provide RTOS-compatible acquire/release bus services for communication peripheral drivers.

Implementing functions to manage the access to communication buses like SMBUS in a multi-tasking environment. These services ensure that only one task can use the bus at a time, preventing conflicts and ensuring data integrity. The acquire function locks the bus for a task, while the release function unlocks it, allowing other tasks to use the bus.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including SMBUS instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL SMBUS functions start with HAL_SMBUS. All HAL SMBUS enum and struct start with hal_smbus.

Other HAL SMBUS changes

Concept

Consideration

Provide APIs for timeout configuration

Add ( STM32_UTILS_I2C_SMBUS_ComputeTimeoutA() / STM32_UTILS_I2C_SMBUS_ComputeTimeoutB()) APIs in the helper files utils_i2c.c/.h to calculate the timeout value based on the RCC clock speed.

Provide APIs for timing calculation

Add ( STM32_UTILS_I2C_ComputeAdvanced() / STM32_UTILS_I2C_ComputeTimingBasic()) APIs in the helper files utils_i2c.c/.h to calculate the timing value using the shared formula with I2C.